#!/usr/bin/env zsh
# I am using zsh instead of bash.  I was having some troubles using bash with
# arrays.  Didn't want to investigate, so I just did zsh
source ~/.dotfiles/zsh/.zsh_profile

if [[ -f ~/.zshrc ]]; then
	rm ~/.zshrc
fi

pushd $DOTFILES
for folder in $(echo $STOW_FOLDERS | sed "s/,/ /g")
do
    # it isn't necessary to pre-define, but it helped in debugging
    sed_expr="s|~|$HOME|g"
   
    # replace tildes with home path expansions
    folder=$(echo "$folder" | sed $sed_expr)
   
    # the syntax is src:dest in the variable expansion
    src=$(echo "$folder" | cut -d":" -f1)
    dest=$(echo "$folder" | cut -d":" -f2)

    # print the planned result
    echo "stow -S $src -t $dest"

    # handle paths in source
    if [[ $src == *"/"* ]]; then
        fname=`basename $src`
        fpath=`dirname $src`
        stow -R -d $fpath -S $fname -t $dest
    else
        stow -R -S $src -t $dest
    fi
    
done
popd

